# encoding: utf8

dic = dict()
f = open("interface.txt","r")

for line in f.readlines():
    line = line.strip()
    if not line:
        continue
    if line.startswith("#"):
        #print("此行是注释",line)
        continue
    #print("11----",line)
    arr = line.split("',")
    #print(arr[0])
    if "^" in arr[0]:
        #url = arr[0][len("url('^"):-1]
        url = arr[0].split("^")[1]
        if "$" in url:
            url = url[:-1]
        
        #f2.write(url)
    else:
        raise Exception("error: url not in array")
        
        #print(url)
    #print(arr[1])
    list = []
    if "#" in arr[1]: # 如果此行包含注释
        mc = arr[1].split("#") #mc是方法和备注，mc[0]是方法, mc[1]是备注
        m = mc[0].strip()
        m = m[:-2]
        list.append(m) #m是方法，把方法追加到list里
        list.append(mc[1])
        #f2.write(m+",")
        print(mc[1])

    else: # 如果没有注释
        m = arr[1][:-2]
        list.append(m)
        list.append("")
        
    dic[url] = list
    print(m)
    

f.close()
f3 = open("paramDic.py","r")
param = []
urlParam = dict()
url = ""
flag = False
isEnd = False
for line in f3.readlines():
    line = line.strip()
    #print("--55--", line);
    if not line:
        continue
    if "}," in line and (not isEnd):
        flag = False
        #print("--60---%s" % str(param))
        urlParam[url] = param
        #print("--62---%s" % str(urlParam))
        param = []
        isEnd = True
        continue
    if flag:
        print("---64---%s" % line)
        param.append(line)
        
    if "\"url\"" not in line and "\"data\"" not in line:
        continue
    if "\"url\"" in line:
        aaa = line.split("39.106.248.147/")
        url = aaa[1][:-2]
        
    if "\"data\"" in line:
        flag = True
        isEnd = False
print("---", str(urlParam))
f3.close()
f2 = open("result.csv","w")

for url,list in dic.items():
    param = urlParam.get(url)
    if param:
        param_str = ",".join(param)
    else:
        param_str = ""
    row = url + "," + list[0] + "," + list[1] + "," + param_str + "\n"
    f2.write(row)
f2.close()